<template>
  <div>
    <van-nav-bar title="注册">
      <template #left>
        <van-icon name="arrow-left" @click="goHome" />
      </template>
    </van-nav-bar>
    <van-form @submit="onSubmit">
      <van-field
        v-model="nickname"
        name="nickname"
        label="昵称"
        placeholder="昵称"
        :rules="[{ required: true, message: '请填写昵称' }]"
      />

      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field
        v-model="phone"
        type="phone"
        name="phone"
        label="手机号"
        placeholder="手机号"
        :rules="[{ required: true, message: '请填手机号' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit">
          提交
        </van-button>
      </div>
    </van-form>
  </div>
</template>
<script>
import Vue from "vue";
import { Notify } from "vant";

import { Form } from "vant";
import { memberRegister } from "../../request/index.js";
export default {
  data() {
    return {
      nickname: "",
      password: "",
      phone: "",
      xinxi: [],
    };
  },
  methods: {
    async onSubmit(values) {
      let res = await memberRegister(values)
        .then((res) => {
          this.$router.push("/loginno");
          console.log(res);
          Notify({ type: "success", message: res.data.msg });
        })
        .catch((err) => {
          Notify({ type: "danger", message: err.data.msg });
        });

      console.log("submit", values);
    },
    goHome() {
      this.$router.go(-1);
    },
  },
};
</script>